#include <iostream>
#include <vector>

using namespace std;


class Solution 
{
public:
	int binarySearch(vector<int>& nums, int target) 
	{
		int left = 0;
		int right = nums.size() - 1;
		
		while (left <= right) 
		{
			int mid = left + (right - left) / 2;
			
			if (nums[mid] == target) 
			{
				return mid;
			}
			else if (nums[mid] < target) 
			{
				left = mid + 1;
			}
			else 
			{
				right = mid - 1;
			}
		}
		
		return left; // 返回插入位置
	}
};

int main() 
{
	Solution sol;
	vector<int> nums = {1, 3, 5, 7};
	int target;
	
	cout << "请输入目标值: ";
	cin >> target;
	
	int result = sol.binarySearch(nums, target);
	cout << "目标值应插入索引: " << result << endl;
	
	return 0;
}

